const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');

Page({
	data: {
		coursearrange_id:0,
		student_id:0,
		clockintime:0,
		coursename:"",
    dataDetail:[],
    studentleave_id:0,
    showBtn:0,//控制按钮显示隐藏
    slid:0  //请假id-可能为空
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		var _coursearrange_id = options.coursearrange_id;
		var _student_id = options.student_id;
		var _clockintime = options.clockintime;
    var _coursename = options.coursename;
    var _slid = options.slid;
		this.setData({
			coursearrange_id:_coursearrange_id,
			student_id:_student_id,
			clockintime:_clockintime,
      coursename:_coursename,
      slid:_slid
		});
		this.getAttendError();
	},
	getAttendError(){
		var that = this;
		http.httpPost(config.getAttendError, {
			coursearrange_id: that.data.coursearrange_id,
			student_id: that.data.student_id,
			clockintime: that.data.clockintime,
      coursename:that.data.coursename,
      slid:that.data.slid
		}, function(e) {
			if (e.code == 1) {
				that.setData({
          dataDetail: e.data,
          studentleave_id:e.data.studentleave_id,
          showBtn:e.data.showBtn
				});
      }
		});
  },
  clickBtn(e){
    var _status = e.currentTarget.dataset.status;
    var that = this;
    http.httpPost(config.updateStudentLeave, {
      studentleave_id:that.data.studentleave_id,
			sastatus: _status
		}, function(e) {
			if (e.code == 1) {
					wx.showToast({
						title: e.msg,
						icon: 'none',
						duration: 2000,
						mask: true
          });
          
          setTimeout(function(){
            wx.reLaunch({
              url: '/supervise/student/leave'
            })
          },2100)
			}
		});


  },
	onReady() {
		if (!app.login()) {
			return;
		}
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})
